package cn.tedu.fresheveryday.service.impl;

import cn.tedu.fresheveryday.mapper.ViewHistoryMapper;
import cn.tedu.fresheveryday.pojo.entity.ViewHistory;
import cn.tedu.fresheveryday.pojo.vo.ViewHistorySimpleVO;
import cn.tedu.fresheveryday.service.IViewHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class HistoryServiceImpl implements IViewHistoryService {
    private final ViewHistoryMapper mapper;

    @Autowired
    public HistoryServiceImpl(ViewHistoryMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public void insert(ViewHistory history) {
        mapper.insert(history);
    }

    @Override
    public List<ViewHistorySimpleVO> select(String userId) {
        return mapper.selectByUserId(userId);
    }

    @Override
    public List<ViewHistory> selectByUserIdAndProductId(String userId, int productId) {
        return mapper.selectByUserIdAndProductId(userId, productId);
    }

    @Override
    public void updateById(String id, LocalDateTime viewTime) {
        mapper.updateById(id, viewTime);
    }

}